#include "stdafx.h"
#include "GCamera.h"

GCamera GCamera::CameraControl;

GCamera::GCamera()
{
	X = Y = 0;

	TargetX = TargetY = NULL;

	TargetMode = TARGET_MODE_NORMAL;
}

GCamera::~GCamera()
{
}

float GCamera::GetTargetModeX()
{
	if (TargetX != NULL)
	{
		if (TargetMode == TARGET_MODE_CENTER)
		{
			return WWIDTH / 2;
		}
	}
	return 0;
}

float GCamera::GetTargetModeY()
{
	if (TargetY != NULL)
	{
		if (TargetMode == TARGET_MODE_CENTER)
		{
			return WHEIGHT / 2;
		}
	}
	return 0;
}

float GCamera::GetX()
{
	    if(TargetX != NULL) 
		{
			if(TargetMode == TARGET_MODE_CENTER) 
			{
				return *TargetX - GetTargetModeX();
			}
			return *TargetX;    
		}
		return X;
}

float GCamera::GetY()
{
	    if(TargetY != NULL) 
		{
			if(TargetMode == TARGET_MODE_CENTER) 
			{
				return *TargetY - GetTargetModeY();
			}
			return *TargetY;    
		}
		return Y;
}

float GCamera::GetMapX()
{
	if(TargetX != NULL) 
	{
		return *TargetX;    
	}
	return X;
}

float GCamera::GetMapY()
{
	if(TargetY != NULL) 
	{
		return *TargetY;    
	}
	return Y;
}

void GCamera::SetPos(int X, int Y)
{
	this->X = X;
	this->Y = Y;
}

void GCamera::SetPosToEnd()
{
	SetPos(MAP_WIDTH * TILE_SIZE * GArea::AreaControl.GetAreaSize() - WWIDTH, 
		MAP_HEIGHT * TILE_SIZE * GArea::AreaControl.GetAreaSize() - WHEIGHT);
}

void GCamera::SetPosToStart()
{
	SetPos(0, 0);
}

void GCamera::SetPosToLeft()
{
	SetPos(0, MAP_HEIGHT * TILE_SIZE * GArea::AreaControl.GetAreaSize() - WHEIGHT);
}

void GCamera::SetPosToRight()
{
	SetPos(MAP_WIDTH * TILE_SIZE * GArea::AreaControl.GetAreaSize() - WWIDTH, 0);
}

void GCamera::SetTarget(float* X, float* Y)
{
	TargetX = X;
	TargetY = Y;
}

void GCamera::SetTarget()
{
	TargetX = &this->X;
	TargetY = &this->Y;
}

void GCamera::SetTargetX(float* X)
{
	TargetX = X;
	TargetY = &this->Y;
}

void GCamera::SetTargetY(float* Y)
{
	TargetX = &this->X;
	TargetY = Y;
}